//
//  ContainerViewController.m
//  DaHaiDouBan
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 Wang Dahai. All rights reserved.
//

#import "ContainerViewController.h"
#import "MoviesViewController.h"
#import "CollectionViewController.h"

@interface ContainerViewController ()

@property (nonatomic, retain) UIButton *button;
@property (nonatomic, retain) MoviesViewController *movieVC;
@property (nonatomic, retain) CollectionViewController *collectionVC;
@property (nonatomic, assign) BOOL isSelected;

@end

@implementation ContainerViewController
- (void)dealloc
{
    [_button release];
    [_collectionVC release];
    [_movieVC release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor lightGrayColor];

    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(0, 0, 30, 30);
    [self.button setBackgroundImage:[UIImage imageNamed:@"btn_nav_list@2x"] forState:UIControlStateNormal];
    [self.button setBackgroundImage:[UIImage imageNamed:@"btn_nav_collection@2x"] forState:UIControlStateSelected];
    
    [self.view addSubview:self.button];
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:self.button] autorelease];

    self.collectionVC = [[CollectionViewController alloc] init];
    [self addChildViewController:self.collectionVC];
    [self.view addSubview:self.collectionVC.view];
    [_collectionVC release];
    
    self.movieVC = [[MoviesViewController alloc] init];
    [self addChildViewController:self.movieVC];
    [self.view addSubview:self.movieVC.view];
    [_movieVC release];
    self.isSelected = NO;
    
}
-(void)buttonAction:(UIButton *)btn
{
    if (self.isSelected == NO) {
        
        [UIView transitionFromView:self.movieVC.view toView:self.collectionVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
            
        }];
        
        
    }else
    {
        [UIView transitionFromView:self.collectionVC.view toView:self.movieVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
            
            
        }];
        
    }
    
    self.isSelected = ! self.isSelected;
    self.button.selected = ! self.button.selected;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
